package mapEditor.common
{
	import flash.display.DisplayObject;
	import flash.geom.Point;

	public class DisplayObjectManager
	{
		public function DisplayObjectManager()
		{
		}
		
		public static function thumbnailShow(dis:DisplayObject, width:Number, height:Number):void
		{
			var newWidth:Number;
			var newHeight:Number;
			var pt:Point=new Point();
			
			if (width <= 0 || height <= 0)
			{
				newWidth = dis.width;
				newHeight = dis.height;
			}
			else
			{
				if (dis.width > dis.height)
				{
					if (dis.width < width)
					{
						newWidth = dis.width;
					}
					else
					{
						newWidth = width;
					}
					
					newHeight = dis.height * (newWidth / dis.width);
				}
				else
				{
					if (dis.height < height)
					{
						newHeight = dis.height;
					}
					else
					{
						newHeight = height;
					}
					
					newWidth = dis.width * (newHeight / dis.height);
				}
				
				if (newWidth > width)
				{
					newWidth = width;
					newHeight = dis.height * (newWidth / dis.width);
				}
				
				if (newHeight > height)
				{
					newHeight = height;
					newWidth = dis.width * (newHeight / dis.height);
				}
				
				if (newWidth < width)
				{
					pt.x = (width - newWidth) / 2;
				}
				
				if (newHeight < height)
				{
					pt.y = (height - newHeight) / 2;
				}
			}
			
			dis.x=pt.x;
			dis.y=pt.y;
			dis.width=newWidth;
			dis.height=newHeight;
		}
	}
}